<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>编辑用户信息</title>
	<link rel="stylesheet" type="text/css" href="/secondhand/css/query.css" />
	<script type="text/javascript" src="/secondhand/js/jquery-3.2.1.js"></script>
</head>
<body>
<div id="top">·当前位置： 用户管理 -- 修改用户</div>
<form>
	<table id="tab" style="margin-top: 30px;border-collapse:separate; border-spacing:0px 10px;">
		<tr>
			<td align="right" style="width: 40%;">用户ID : </td>
			<td align="left">&nbsp;<input type="text" id="userid" readonly="readonly"/></td>
		</tr>
		<tr>
			<td align="right" style="width: 40%;">用户名 : </td>
			<td align="left">&nbsp;<input type="text" id="username" readonly="readonly"/></td>
		</tr>
		<tr>
			<td align="right" style="width: 40%;">昵称 : </td>
			<td align="left">&nbsp;<input type="text" id="userfullname"/><span style="color: red"> *</span></td>
		</tr>
		<tr>
			<td align="right" style="width: 40%;">密码 : </td>
			<td align="left">&nbsp;<input type="password" id="password" placeholder="不修改请留空"/></td>
		</tr>
		<tr>
			<td align="right" style="width: 40%;">手机号码 : </td>
			<td align="left">&nbsp;<input type="text" id="phone"/><span style="color: red"> *</span></td>
		</tr>
		<tr>
			<td colspan="2">
				<input style="width: 60px;" type="submit" value="提交" />
				<a href="/secondhand/toList.goods?pageNo=1&likeValue=">
				<input style="width: 60px;" type="button" value="返回" />
				</a>
			</td>
		</tr>
	</table>
</form>

<script>
	$(function() {
		// 页面加载时获取用户信息
		$.post("/secondhand/viewUser.User", function(data) {
			$("#userid").val(data.user.userid);
			$("#username").val(data.user.username);
			$("#userfullname").val(data.user.userfullname);
			$("#phone").val(data.user.phone);
		});

		// 表单提交处理
		$("form").submit(function(e) {
			e.preventDefault();

			// 简单验证
			if ($("#userfullname").val().trim() == "") {
				alert("昵称不能为空");
				return false;
			}
			if ($("#phone").val().trim() == "") {
				alert("手机号码不能为空");
				return false;
			}

			// 提交更新
			$.post("/secondhand/updateUser.User", {
				userfullname: $("#userfullname").val(),
				phone: $("#phone").val(),
				password: $("#password").val()
			}, function() {
				alert("用户信息更新成功");
				window.top.location.href = "/secondhand/login.html";
			},);

			return false;
		});
	});
</script>
</body>
</html>
